package com.lzh.others.basejava.Exception_12;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Logger;

/**
 * @author by lzh
 * @Classname LoggingException2
 * @Description 更常见的情形是我吗需要捕获和记录其他人编写的异常，因此我们必须在异常处理程序中生成日志
 * @Date 2022/6/28 22:11
 */
public class LoggingExceptions2 {
    private static final Logger logger = Logger.getLogger("LoggingExceptions2");

    static void logException(Exception e) {
        StringWriter stringWriter = new StringWriter();
        e.printStackTrace(new PrintWriter(stringWriter));
        logger.severe(stringWriter.toString() + "test");
    }

    public static void main(String[] args) {
        try {
            throw new NullPointerException();
        } catch (NullPointerException e) {
            e.printStackTrace();
            System.out.println("----------------");
            logException(e);
        }
    }
}
